﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DAO; 

namespace OnlineDigitalCameraWebsite
{
    public partial class Template : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
             
        }

        protected void btnTimKiem_Click(object sender, EventArgs e)
        {
            //if (txtTuKhoa.Text.Trim() != "" || txtTuKhoa.Text.Trim()!= string.Empty)
            //{
                string tukhoa = Utils.ConvertToUnSign(txtTuKhoa.Text.Trim()).ToLower();
                string keys = txtTuKhoa.Text.Trim();
                SearchCountBUS sBUS = new SearchCountBUS();
                SearchCount sc = new SearchCount();
                sc = sBUS.GetByKeys(keys);
                if (sc != null)
                {
                    // tang so lan tim kiem len
                    sBUS.Edit_Count(keys);
                }
                else
                {
                    // chua co thi them vao csdl
                    sc = new SearchCount();
                    sc.keys = keys;
                    sc.count = 1;
                    sBUS.Insert(sc);
                }
                int giatrichon = int.Parse(ddlCategory.SelectedValue.ToString()); // lay gia tri dc chon o combobox
                if (giatrichon == 0)
                {
                    LoadCamera(tukhoa);
                    LoadAcc(tukhoa);
                    LoadLens(tukhoa);
                    Response.Redirect("/DanhMuc.aspx?cate=danhmuc");
                }
                else if (giatrichon == 1)
                {
                    // load camera
                    LoadCamera(tukhoa);
                    Response.Redirect("/DanhMuc.aspx?cate=camera");

                }
                else if (giatrichon == 2)
                {
                    //load acc 
                    LoadAcc(tukhoa);
                    Response.Redirect("/DanhMuc.aspx?cate=accessories");
                }
                else
                {
                    // load lens
                    LoadLens(tukhoa);
                    Response.Redirect("/DanhMuc.aspx?cate=lens");
                }
            //}
            //else
            //{
            //    ShowMessage("Nhập từ khóa tìm kiếm");
            //}
        }

        public void ShowMessage(string Content)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script language='javascript'>alert('" + Content + "');</script>");
        }

        private void LoadCamera(string tukhoa)
        {
            CameraBUS cBUS = new CameraBUS();
            List<Camera> list = new List<Camera>();
            DanhMuc.ListCamera = cBUS.GetListSearch(tukhoa);
            
        }

        private void LoadAcc(string tukhoa)
        {
            AccessoriesBUS cBUS = new AccessoriesBUS();
            List<Accessory> list = new List<Accessory>();
            DanhMuc.ListAccessory = cBUS.GetListSearch(tukhoa);
           
        }

        private void LoadLens(string tukhoa)
        {
            LensBUS cBUS = new LensBUS();
            List<Lens> list = new List<Lens>();
            DanhMuc.ListLens = cBUS.GetListSearch(tukhoa);
           
        } 
    }
}